package com.nf.health.app.healthstate.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.homepage.activity.SystemSchemeActivity;
import com.nf.health.app.models.HealthStateInfo;
import com.nf.health.app.utils.ActivityUtils;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Jason on 2016/3/31.
 */
public class ItemSchemeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    List<HealthStateInfo.SchemeListEntity> schemeListEntities;

    Activity act;
    public ItemSchemeAdapter(List<HealthStateInfo.SchemeListEntity> schemeListEntities ,Activity act) {
        this.schemeListEntities = schemeListEntities;
        this.act = act;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View rootView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_healthy_state_child3, parent, false);
        return new ItemSchemeViewHolder(rootView);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ItemSchemeViewHolder itemHolder = (ItemSchemeViewHolder) holder;
        itemHolder.tvTitle.setText(schemeListEntities.get(position).getName());
        itemHolder.tvContent.setText(schemeListEntities.get(position).getDetail());
    }

    @Override
    public int getItemCount() {
        return schemeListEntities == null ? 0 : schemeListEntities.size();
    }

    class ItemSchemeViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_title)
        TextView tvTitle;
        @Bind(R.id.tv_content)
        TextView tvContent;
        @Bind(R.id.btn_add)
        TextView btnAdd;

        public ItemSchemeViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            btnAdd.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ActivityUtils.showActivity(act,SystemSchemeActivity.class);
                }
            });
        }
    }
}
